//
// Created by francklinson on 2021/11/28 AT 15:01.
// May Saint Diana bless you!
//

#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>
#include <string>

using namespace std;

class Solution {
public:
    vector<string> findOcurrences(string text, string first, string second) {
        // 切分string，逐个匹配
        vector<string> strVector;
        int start = 0;
        for (int i = 0; i < text.size(); ++i) {
            if (i == text.size() - 1 || text[i + 1] == ' ') {
                strVector.push_back(text.substr(start, i - start + 1));
                start = i + 2;
            }
        }
        vector<string >ans;
        for (int i = 0; i < strVector.size()-2; ++i) {
            if (strVector[i]==first && strVector[i+1]==second)
                ans.push_back(strVector[i+2]);
        }
        return ans;
    }
};

int main() {
    Solution solution;
    vector<string> ans = solution.findOcurrences("alice is a good girl she is a good student",
                                                 "a", "good");
    for (const string &x: ans) cout << x << endl;
    return 0;
}

